package com.bestcem.xm.om.dao.impl;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.om.dao.OmIndustryDao;
import com.bestcem.xm.om.dao.mapper.OmIndustryMapper;
import com.bestcem.xm.om.entity.OmIndustry;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * OmIndustryDaoImpl
 *
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/10/12 18:09
 */
@Repository
public class OmIndustryDaoImpl implements OmIndustryDao {
    @Resource
    private OmIndustryMapper omIndustryMapper;

    @Override
    public int deleteById(String id) {
        return omIndustryMapper.deleteById(id);
    }

    @Override
    public String insert(OmIndustry omIndustry) {
        String objectId = ObjectId.next();
        omIndustry.setId(objectId);
        omIndustry.setCreateTime(LocalDateTime.now());
        omIndustry.setUpdateTime(omIndustry.getCreateTime());
        omIndustryMapper.insert(omIndustry);
        return objectId;
    }

    @Override
    public OmIndustry findById(String id) {
        return omIndustryMapper.findById(id);
    }

    @Override
    public int updateById(OmIndustry omIndustry) {
        omIndustry.setUpdateTime(LocalDateTime.now());
        return omIndustryMapper.updateById(omIndustry);
    }

    @Override
    public OmIndustry findByCode(Integer code) {
        return omIndustryMapper.findByCode(code);
    }

    @Override
    public List<OmIndustry> listByParam(String id, Integer code, String name, Integer order) {
        return omIndustryMapper.listByParam(id, code, name, order);
    }

    @Override
    public List<OmIndustry> listByIds(Collection<String> industryIds) {
        return omIndustryMapper.listByIds(industryIds);
    }

    @Override
    public List<OmIndustry> listAll() {
        return omIndustryMapper.listAll();
    }

    @Override
    public Integer updateNameByCode(int code, String name) {
        return omIndustryMapper.updateNameByCode(code,name);
    }
}
